package com.itheima.app.controller;

import com.itheima.app.manager.MakeFriendManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class MakeFriendController {

    @Autowired
    MakeFriendManager makeFriendManager;

    //今日佳人
    @GetMapping("/tanhua/todayBest")
    public ResponseEntity findTodayBest(){
        return makeFriendManager.findTodayBest();
    }

    //推荐用户列表
    @GetMapping("/tanhua/recommendation")
    public ResponseEntity findRecommendUserByPage(
            @RequestParam(value = "page",defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10") Integer pageSize){
        return makeFriendManager.findRecommendUserByPage(pageNum,pageSize);
    }

    //推荐用户详情
    @GetMapping("/tanhua/{jiaRenId}/personalInfo")
    public ResponseEntity findPersonalInfo(@PathVariable Long jiaRenId){
        return makeFriendManager.findPersonalInfo(jiaRenId);
    }

    //最近访客
    @GetMapping("/movements/visitors")
    public ResponseEntity findVisitorsTop5(){
        return makeFriendManager.findVisitorsTop5();
    }

    //上报地理位置
    @PostMapping("/baidu/location")
    public void saveUserLocation(@RequestBody Map<String,String> map){
        System.out.println(map);
        Double longitude = Double.parseDouble(map.get("longitude"));
        Double latitude = Double.parseDouble(map.get("latitude"));
        String addrStr = map.get("addrStr");

        makeFriendManager.saveUserLocation(longitude,latitude,addrStr);

    }

    //搜附近
    @GetMapping("/tanhua/search")
    public ResponseEntity searchNear(String gender,Integer distance){
        return makeFriendManager.searchNear(gender,distance);
    }

    //查询陌生人问题
    @GetMapping("/tanhua/strangerQuestions")
    public ResponseEntity findStrangerQuestion(Long userId){
        return makeFriendManager.findStrangerQuestion(userId);
    }
}
